<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <!-- 引入bootstarp -->
    <script type="text/javascript" src="../js/bootstrap3/js/bootstrap.js"></script>
    <link rel="stylesheet" href="../js/bootstrap3/css/bootstrap.css">
    <!-- 引入bootstrap table的css、js -->
    <link type="text/css" rel="stylesheet" href="../js/bootstrap-table/bootstrap-table.css">
    <script type="text/javascript" src="../js/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="../js/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <!-- 引入bootstrap datetime的css、js -->
    <link type="text/css" rel="stylesheet" href="../js/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
    <script type="text/javascript" src="../js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="../js/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>

    <script src="../js/bootstrap-bootbox/bootbox.all.min.js"></script>
    <script src="../js/bootstrap-fileinput/js/fileinput.js"></script>
    <script src="../js/bootstrap-fileinput/js/locales/zh.js"></script>
    <link rel="stylesheet" href="../js/bootstrap-fileinput/css/fileinput.css">
</head>
<body>
<form class="form-inline">
    <div class="form-group">
        <label for="startPrice">
            <font color="red">时间</font>
        </label>
        <input type="text" class="date form-control" id="startPrice" placeholder="请输入开始时间">
        <i class="glyphicon glyphicon-calendar"></i>
        <input type="text" class="date form-control" id="endPrice" placeholder="请输入结束时间">
    </div>
    <button type="button" class="btn btn-primary glyphicon glyphicon-search" onclick="shopTable()">搜索</button>

</form>
<table class="table" id="shopTable"></table>
</body>
<script>
    $(function () {
        tables();
        /*findSaveProduct();*/

    })
    /**
     * 初始化页面加载所有订单信息
     */
    function tables(){
        $("#shopTable").bootstrapTable({
            url:'../wjs/findOrder',
            type:'post',
            pagination:true, //开启分页
            //pageList:[1, 5, 10, 15,50],//分页组件
            pageNumber:1,
            pageSize:10,//默认每页条数
            sidePagination:'server',//分页方式：client客户端分页，server服务端分页
            striped:true,//条纹表格
            clickToSelect: true,
            queryParams:function(){
                return {
                    page:this.pageNumber,
                    rows:this.pageSize,
                    startDate:$("#startTime").val(),
                    endDate:$("#endTime").val()
                };
            },
            columns:[
                {checkbox:true},
                {field:'orderNo',title:'订单编号',width:80},
                {field:'userName',title:'用户昵称',width:80},
                {field:'userImg',title:'用户头像',width:80,formatter:function(value,row,index){
                        return "<img src='"+value+"' width='50px' height='50px'/>";
                    }},
                {field:'orderPrice',title:'订单总价',width:80},
                {field:'productName',title:'购买商品',width:80},
                {field:'orderCreateTime',title:'订单生成时间',width:80},
                {field:'productCount',title:'商品数量',width:80},
                {field:'orderStatus',title:'订单状态',width:80,formatter:function (value,row,index) {
                    if (value == 1){
                        return "未付款"
                    }
                    if (value == 2){
                        return "已付款"
                    }if (value == 3){
                            return '<a href="javascript:openDialog('+row.productId+');">'+"待评价"+'</a>';
                    }if (value == 4){
                            return "已评价";
                        }
                    }}
            ],
        })
    }

    function searchUserShop() {
        $("#userShopTable").bootstrapTable('refresh');
    }

    //打开
    function openDialog(id){
        alert(id)
        bootbox.dialog({
            title:'<i class="glyphicon glyphicon-book"></i>用户评价',
            message:loadPage('../page/addproduct'),
            size:'large',
            buttons:{
                cancel:{
                    label: "取消",
                    className: 'btn-danger',
                    callback: function(){
                    }
                },
                ok:{
                    label: "保存",
                    className: 'btn-info',
                    callback: function(){
                        saveBook(id);
                    }
                }
            }
        })
    }
    //新增
    function saveBook(id){
        alert(id)
        $.ajax({
            url:'../wjs/addlun?productId='+id,
            type:'post',
            data:$("#bookForm").serialize(),
            dataType:'json',
            success:function(data){
                if (data) {
                    $('#shopTable').bootstrapTable('refresh');
                }else{
                    bootbox.alert({
                        message: "保存失败",
                        size: 'small'
                    });
                }
            }
        })
    }
    //跳转页面
    function loadPage(url){
        var res = '';
        $.ajax({
            url:url,
            async:false,
            success:function(data){
                res = data;
            }
        });
        return res;
    }

    /**
     * 商品评价
     */
    /*function findSaveProduct(){
        var productId=sessionStorage.getItem("productId");

        $.ajax({
            url:'../wjs/findSaveProduct',
            data:{productId:productId},
            type: "post",
            success:function(data) {

            }
        })
    }*/
</script>
</html>